package com.ruoyi.reservationserver.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.reservationserver.entity.Reservations;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.domain.Pageable;

import java.util.List;

/**
 * 预约表(Reservations)表数据库访问层
 *
 * @author makejava
 * @since 2023-07-04 16:21:49
 */
@Mapper
public interface ReservationsDao extends BaseMapper<Reservations> {

//    @Select("SELECT * FROM Reservations WHERE account LIKE '%${account}%'")
    @Select("SELECT r.* FROM reservations r JOIN court c ON r.court_id = c.court_id WHERE c.court_name LIKE '%${courName}%'")
    List<Reservations> selectReservationsByCourtName(String courtName);


    @Select("SELECT SUM(reservation_num) FROM reservations")
    Integer getReservationNumSum();
    /**
     * 通过ID查询单条数据
     *
     * @param reservationId 主键
     * @return 实例对象
     */
    Reservations queryById(Integer reservationId);

    /**
     * 查询指定行数据
     *
     * @param reservations 查询条件
     * @param pageable         分页对象
     * @return 对象列表
     */
    List<Reservations> queryAllByLimit(Reservations reservations, @Param("pageable") Pageable pageable);

    /**
     * 统计总行数
     *
     * @param reservations 查询条件
     * @return 总行数
     */
    long count(Reservations reservations);

    /**
     * 新增数据
     *
     * @param reservations 实例对象
     * @return 影响行数
     */
    int insert(Reservations reservations);

    /**
     * 批量新增数据（MyBatis原生foreach方法）
     *
     * @param entities List<Reservations> 实例对象列表
     * @return 影响行数
     */
    int insertBatch(@Param("entities") List<Reservations> entities);

    /**
     * 批量新增或按主键更新数据（MyBatis原生foreach方法）
     *
     * @param entities List<Reservations> 实例对象列表
     * @return 影响行数
     * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常，请自行校验入参
     */
    int insertOrUpdateBatch(@Param("entities") List<Reservations> entities);

    /**
     * 修改数据
     *
     * @param reservations 实例对象
     * @return 影响行数
     */
    int update(Reservations reservations);

    /**
     * 通过主键删除数据
     *
     * @param reservationId 主键
     * @return 影响行数
     */
    int deleteById(Integer reservationId);

}

